#pragma once

namespace ui_comp {
	class MarkDownModel;
	class MarkDownView;
	class MardDownCanvas : public ui::Box {
	public:
		MardDownCanvas(MarkDownView* view);
		virtual ~MardDownCanvas();

		bool Load(const std::string& markdown);
		bool LoadFile(const std::wstring& sFile) {};
	protected:
		bool LoadModel();
	protected:
		virtual void Paint(IRenderContext* pRender, const UiRect& rcPaint) override;
		virtual void PaintCanvas(IRenderContext* pRender);		//not override
	private:
		MarkDownModel* model_{ nullptr };
		MarkDownView* view_{ nullptr };

		std::wstring m_sTextColor = L"textdefaultcolor";
		std::wstring m_sLinkTextColor = L"linkblue";
	};


	class MarkDownView :public ui::ScrollableBox {
	public:
		MarkDownView() : ScrollableBox(new VLayout) {
			SetPaddingRect({ 4,2,4,2 });
			SetBkColor(L"white");
			EnableScrollBar(true, false);
			canvas_ = new MardDownCanvas(this);
			Add(canvas_);
		};
		virtual ~MarkDownView() {};

		bool Load(const std::string& markdown) {
			assert(canvas_);
			if (canvas_)
				return canvas_->Load(markdown);
			return false;
		};
		bool LoadFile(const std::wstring& sFile) {
			assert(canvas_);
			if (canvas_)
				return canvas_->LoadFile(sFile);
			return false;
		};

	protected: 
		MardDownCanvas* canvas_{ nullptr };
	};
}
